<?php


namespace App\Extensions\Grid\Displayers;


use Encore\Admin\Grid\Column\Help;
use Encore\Admin\Grid\Displayers\AbstractDisplayer;

class HelpTip extends AbstractDisplayer
{
    public function display($callback = '', $default = '')
    {
        if ($callback instanceof \Closure) {
            $callback = $callback->bindTo($this->row);
            $default = call_user_func_array($callback, [$this->row]);
        } elseif ($callback && is_string($callback) && $this->row->$callback) {
            $default = $this->row->$callback;
        }
        if (!$default) {
            return $this->value;
        }
        return sprintf('%s%s',
            $this->value,
            (new Help($default))->render()
        );
    }

}
